﻿using Gnivc.CarDealership.Api.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using static Gnivc.CarDealership.Api.Infrastructure.Persistence.PersistenceConstants;

namespace Gnivc.CarDealership.Api.Infrastructure.Persistence.Configurations;

public class VehicleConfiguration : IEntityTypeConfiguration<Vehicle>
{
    public void Configure(EntityTypeBuilder<Vehicle> builder)
    {
        builder.ToTable(TableNames.Vehicle, SchemaNames.Retail)
            .HasKey(x => x.Id);

        builder.HasOne(x => x.Model)
            .WithMany(x => x.Vehicles)
            .HasForeignKey(x => x.ModelId);

        builder.OwnsOne(x => x.Engine);
    }
}
